package com.hd.pzhwlxt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hd.pzhwlxt.pojo.VehicleRepairMaterialInfo;
import com.hd.pzhwlxt.service.VehicleRepairMaterialInfoService;
import com.hd.pzhwlxt.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @create: 2022-09-22 16:38
 * @author: 怀念天空
 * @Description: 车辆耗材信息,需要维修工信息（根据员工编号查询），车辆信息（根据维修编号查询）
 * 耗材信息会单独写进耗材表
 */
@RestController
@RequestMapping("vehicleMaterial")
public class VehicleRepairMaterialController {

    @Autowired
    private VehicleRepairMaterialInfoService vehicleRepairMaterialInfoService;

    @GetMapping("/get")
    public Response<Object> getAllConsumablesInfo(@RequestParam(value = "pageNum",required = false) Integer pageNum,@RequestParam(value = "pageSize",required = false) Integer pageSize){
        if (pageNum == null || pageSize == null){
            List<VehicleRepairMaterialInfo> result = vehicleRepairMaterialInfoService.getAllInfo();
            if(result!=null){
                return Response.createSuccessResponse("查询成功", result);
            }
        }else{
            Page<VehicleRepairMaterialInfo> result = vehicleRepairMaterialInfoService.getAllInfoPage(pageNum,pageSize);
            return Response.createSuccessResponse("查询成功", result);
        }
        return Response.createErrorResponse("查询失败");
    }

    @GetMapping("/get/{id}")
    public Response<VehicleRepairMaterialInfo> getConsumablesInfoById(@PathVariable Integer id){
        VehicleRepairMaterialInfo result = vehicleRepairMaterialInfoService.getInfoById(id);
        if(result!=null){
            return Response.createSuccessResponse("查询成功", result);
        }
        return Response.createErrorResponse("查询失败");
    }
}
